<?php
set_time_limit(0);
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
require_once './Classes/PHPExcel.php';

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Openid')
->setCellValue('B1', '奖品类型')
->setCellValue('C1', '姓名')
->setCellValue('D1', '手机')
->setCellValue('E1', '地址')
->setCellValue('F1', '参与时间')
;
include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$index=2;
$query=$mysqli->query("SELECT * FROM jiang  ");
$jName=array(
		1=>'金元宝1枚',
		2=>'海信智能蓝牙音箱1台',
		3=>'烤涮一体机1台',
		4=>'蓝牙无线鼠标1个',
		5=>'100元优惠券1张'
);
while ($list=$query->fetch_assoc()){
	
	$name=$phone=$dizhi='';
		
	$queryU=$mysqli->query("SELECT * FROM uinfo where openid='".$list['openid']."' limit 0,1");
	
	if($queryU->num_rows>0){
		$getU=$queryU->fetch_array();
		$name=$getU['name'];
		$phone=$getU['phone'];
		$dizhi=$getU['dizhi'];
	}
	
					$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$index, $list['openid'])
					->setCellValue('B'.$index, $jName[$list['lei']])
					->setCellValue('C'.$index, $name)
					->setCellValue('D'.$index, $phone)
					->setCellValue('E'.$index, $dizhi)
					->setCellValue('F'.$index, $list['createtime'])
					;
					$index++;
					 
					
} 
$mysqli->close();


$objPHPExcel->getActiveSheet()->setTitle('用户信息');

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="用户信息.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
//$objWriter->save();
exit;
?>